package com.hjx.dao.Impl;

import com.hjx.dao.jojjle.userDao;
import com.hjx.pojo.User;
import com.hjx.util.JdbcUtil;

import java.sql.ResultSet;
import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.CountDownLatch;

public class userImpl implements userDao {
    private  boolean isValide=false;

    @Override
    public List<User> getUser(String username)throws Exception{
        List<User> userList=new ArrayList<>();
        ResultSet resultSet=null;
        Object[] params=new Object[]{
            username
        };
//        调用util获取用户信息
        String sql="select user,pass from user where user=?";
        //执行操作前，先创建连接对象
        JdbcUtil.createConnection();
        resultSet= JdbcUtil.find(params,sql);

        while(resultSet.next()){
            User user=new User();
            user.setUser(resultSet.getString("user"));
            user.setPass(resultSet.getString("pass"));
            //将查询出来的user对象存入list集合中
            userList.add(user);
        }
//        关闭资源
        JdbcUtil.closeResources(resultSet);
        return userList;
    }

    @Override
    public int addUser(String[] args) throws Exception {
        int count=0;
        String sql="insert into user(user,pass,order_id,tel,role) values('"+args[0]+"'"+","+"'"+args[1]+"'"+","+"'"+args[2]+"'"+","+"'"+args[3]+"'"+","+"'"+args[4]+"'"+")";
        System.out.println(sql);
        JdbcUtil.createConnection();
        count= JdbcUtil.Change(null,sql);

        JdbcUtil.closeResources(null);
        return count;
    }
}
